package com.qf.main.content.controller;

import com.qf.common.base.result.ResponseResult;
import com.qf.main.content.common.qo.HomePageSlideshowQo;
import com.qf.main.content.entity.HomePageSlideshow;
import com.qf.main.content.service.HomePageSlideshowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 首页轮播图(HomePageSlideshow)表控制层
 *
 * @author makejava
 * @since 2024-01-20 10:26:33
 */
@RestController
@RequestMapping("/homepage/slideshow")
@Api(tags = "轮播图")
@CrossOrigin
public class HomePageSlideshowController{

    @Resource
    private HomePageSlideshowService homePageSlideshowService;

    @PostMapping("/save")
    @ResponseBody
    @ApiOperation("添加轮播图")
    public ResponseResult<Integer> saveHomePageSlideshow(@RequestBody HomePageSlideshowQo homePageSlideshowQo){
        Integer integer = homePageSlideshowService.insertHomePageSlideshowService(homePageSlideshowQo);
        return ResponseResult.success(integer);
    }

    @PostMapping("/upload")
    @ResponseBody
    @ApiOperation("上传图片")
    public ResponseResult<String> uploadImage(@RequestParam("file") MultipartFile file){

        String upload =homePageSlideshowService.uploadImage(file);

        return ResponseResult.success(upload);
    }
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation("根据图片名查询信息")// 修改的时候输入用户名是自动填充旧信息
    public ResponseResult<HomePageSlideshow> getHomePageSlideshow(@RequestParam("slideshowName") String slideshowName ){
        HomePageSlideshow homePageSlideshow = homePageSlideshowService.getHomePageSlideshow(slideshowName);
        return ResponseResult.success(homePageSlideshow);
    }

    @PutMapping("/edit")
    @ResponseBody
    @ApiOperation("修改轮播图信息")
    public ResponseResult<Integer> editHomePageSlideshow(@RequestBody HomePageSlideshowQo homePageSlideshowQo){
        Integer integer = homePageSlideshowService.modifyHomePageSlideshow(homePageSlideshowQo);
        return ResponseResult.success(integer);
    }

    @DeleteMapping("/erase ")
    @ResponseBody
    @ApiOperation("通过id删除轮播图")
    public ResponseResult<Integer> erasePageSlideshow(@RequestParam("id") Integer id){
        return ResponseResult.success(homePageSlideshowService.removeHomePageSlideshow(id));
    }









}

